using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Web.Core;

namespace Yuanlin.Business
{
	[ParseChildren( true ),PersistChildren( false )]
	public class LoginView : Control, INamingContainer
	{
        private ITemplate anonymousTemplate;
        private ITemplate loggedInTemplate;

		protected override void CreateChildControls() 
		{
			Controls.Clear();

			ITemplate template  = null;

			if((HttpContext.Current.User as YuanlinUser).IsAnonymous)
			{
				template = AnonymousTemplate;
			}
			else
			{
				template = LoggedInTemplate;				
			}

			if(template != null)
			{
				Control cntrl = new Control();
				template.InstantiateIn(cntrl);
				Controls.Add(cntrl);
			}

		}
	
        [Browsable(false), DefaultValue((string)null), PersistenceMode(PersistenceMode.InnerProperty), TemplateContainer(typeof(LoginView))]
		public ITemplate AnonymousTemplate 
		{
			get 
            {
                return anonymousTemplate;
            }
			set 
            {
                anonymousTemplate = value;
            }
		}

        [Browsable(false), DefaultValue((string)null), PersistenceMode(PersistenceMode.InnerProperty), TemplateContainer(typeof(LoginView))]
		public ITemplate LoggedInTemplate 
		{
			get 
            {
                return loggedInTemplate;
            }
			set 
            {
                loggedInTemplate = value;
            }
		}
	}
}

 
